package com.plian.system.service.hr.staff.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.hr.staff.TechnicalQualification;
import com.plian.system.mapper.hr.staff.TechnicalQualificationMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.hr.staff.ITechnicalQualificationService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 专业技术资格 服务实现类
 *
 * @author gangan
 * @since 2019-09-30
 */
@Service
@AllArgsConstructor
public class TechnicalQualificationServiceImpl extends BaseServiceImpl<TechnicalQualificationMapper, TechnicalQualification> implements ITechnicalQualificationService {

	@Override
	public List<TechnicalQualification> ListByPid(Long pid) {
		return list(new LambdaQueryWrapper<TechnicalQualification>().eq(TechnicalQualification::getIsDeleted, 0).eq(TechnicalQualification::getStaffFilesId, pid));
	}

	@Override
	public Boolean deleteLogicStaffFilesId(List<Long> ids) {
		LambdaQueryWrapper<TechnicalQualification> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(TechnicalQualification::getStaffFilesId, ids);
		List<TechnicalQualification> technicalQualifications = list(queryWrapper);
		if (CollectionUtil.isNotEmpty(technicalQualifications)){
			return deleteLogic(technicalQualifications.stream().map(TechnicalQualification::getId).collect(Collectors.toList()));
		}
		return true;
	}
}
